多语言 quarto blog

babelquarto

quarto
Author

Tony D

Published

July 3, 2025

A guide to creating a multi-language Quarto blog using the babelquarto R package.

This document provides a step-by-step guide to creating a multi-language blog using Quarto and the babelquarto R package. It covers the entire process, from installing and loading the necessary packages to setting up the main and additional languages. The guide also explains how to modify the _quarto.yml file for language-specific configurations, create new language versions of your .qmd files, and render the final website. It also suggests using LLMs for translation to streamline the content creation process.

1 install package

Code
pak::pak("ropensci-review-tools/babelquarto")

2 load package

Code
library(babelquarto)
library(fs)

3 set main language

Code
website_dir=getwd()
Code
register_main_language(
  main_language = "en",
  project_path = website_dir
)

4 add new language

Code
register_further_languages(c("cn"), website_dir)

5 change _quarto.yml if needed

Code
babelquarto:
  languagecodes:
  - name: cn
    text: "中文"
  - name: en
    text: "EN"
  mainlanguage: 'en'
  languages: ['cn']
title-cn: title in cn
description-cn: description in cn
author-cn: author in cn
lang: en

6 add new language qmd

file name example:for example “index.cn.qmd”

using LLM to create new language qmd file

“translate all qmd to chinese and write to new qmd file.file name example index.cn.qmd ellmer.cn.qmd and so on” in gemini

7 render all document

7.1 add site url to system environment before render

Code
Sys.setenv(BABELQUARTO_CI_URL="https://jcfly3000.github.io/into_AI/")
Code
Sys.getenv("BABELQUARTO_CI_URL")

7.2 we use babelquarto::render_website().

we need to render the .qmd files to HTML. If you are used to using Quarto, you may expect to do this with quarto render or quarto preview, but those do not work with babelquarto.

Code
babelquarto::render_website()

8 view

Now we’d like to view the rendered website in a browser. Once again, quarto preview cannot be used here. Instead, use servr::httw().

Code
servr::httw(path(website_dir, "docs"))

9 Reference

https://github.com/joelnitta/example-babelquarto

https://joelnitta.com/posts/2024-12-06_babelquarto/

https://docs.ropensci.org/babelquarto/